package cloud.xcan.angus.core.tester.interfaces.config;

import cloud.xcan.angus.core.tester.interfaces.config.facade.SettingUserFacade;
import cloud.xcan.angus.core.tester.interfaces.config.facade.vo.setting.UserApiClientProxyUpdateDto;
import cloud.xcan.angus.core.tester.interfaces.config.facade.vo.setting.UserApiProxyEnabledDto;
import cloud.xcan.angus.core.tester.interfaces.config.facade.vo.setting.UserApiProxyVo;
import cloud.xcan.angus.remote.ApiLocaleResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Setting User", description = "User-specific configuration management system. Provides user-specific configuration access for personalized settings within authorized limits")
@Validated
@RestController
@RequestMapping("/api/v1/setting/user")
public class SettingUserRest {

  @Resource
  private SettingUserFacade settingUserFacade;

  @Operation(summary = "Update user API proxy configuration", operationId = "setting:user:apis:proxy:update")
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "User API proxy configuration updated successfully")})
  @PatchMapping("/apis/proxy")
  public ApiLocaleResult<?> proxyUpdate(@Valid @RequestBody UserApiClientProxyUpdateDto dto) {
    settingUserFacade.proxyUpdate(dto);
    return ApiLocaleResult.success();
  }

  @Operation(summary = "Enable user API proxy service", operationId = "setting:user:apis:proxy:enabled")
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "User API proxy service enabled successfully")})
  @PatchMapping("/apis/proxy/enabled")
  public ApiLocaleResult<?> proxyEnabled(@Valid @RequestBody UserApiProxyEnabledDto dto) {
    settingUserFacade.proxyEnabled(dto);
    return ApiLocaleResult.success();
  }

  @Operation(summary = "Get user API proxy configuration details", operationId = "setting:user:apis:proxy:detail")
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "User API proxy configuration retrieved successfully"),
      @ApiResponse(responseCode = "404", description = "User API proxy configuration not found")})
  @GetMapping(value = "/apis/proxy")
  public ApiLocaleResult<UserApiProxyVo> proxyDetail() {
    return ApiLocaleResult.success(settingUserFacade.proxyDetail());
  }

}
